const Router = require('koa-router');
const router = new Router();
const {db,Op,QueryTypes } = require("../../models/db");
// 停用
router.post('/subject/stop', async ctx => {
    let user = ctx.user
    let tenantId = ctx.user.tenantId;
    let body = ctx.request.body
    let state = body.state
    let id = body.id
    let model = await db.models['category'].findOne({
        where: {
            tenantId,
            id
        }
    })
    if(!model) return ctx.err('未找到数据')
    if(model.isInit) {
        return ctx.err('不能修改系统科目状态')
    }
    if(state === '启用') {
        model.state = '停用'
    }
    if(state === '停用') {
        model.state = '启用'
    }
    await model.save()
    let str = state==='启用'?'停用':'启用'
    return ctx.suc('已' + str)
})

module.exports = router;